///////////////////////////////////////////////////////////////
// File: "CProfile.h"
// Author: Ryan Burkevich (RB)
// Purpose: To contain all profile functionality.
///////////////////////////////////////////////////////////////

#include "CProfile.h"
#include "../Wrappers/CSGD_TextureManager.h"

CProfile::CProfile()
{
	m_unRefCount = 1;
	m_unScore = 0;
	m_unCurrentLevel = 1;
	m_nCurrentPwrUp = 7;
	m_unWhichLevelPlaying = 1;
	m_dwColor = 0xff00ff00; 
	m_nColor = GREEN;

	for(int i = 0; i < 7; i++)
		m_vPowerUpList.push_back(false);

	tTrophy tTrophy;
	tTrophy.bTrophy1 = false;
	tTrophy.bTrophy2 = false;
	tTrophy.bTrophy3 = false;

	for(int i = 1; i < 11; i++)
	{
		sprintf_s(tTrophy.szLevel, "Level%iTrophies", i);
		m_vTrophyList.push_back(tTrophy);
	}

	m_bHasItem = false;
	m_bRotateItem = false;

	tItem tItem;
	tItem.nItemID = -1;
	tItem.tPos.fX = 0;
	tItem.tPos.fY = 0;
	tItem.fScaleX = 1;
	tItem.fScaleY = 1;

	for(int i = 0; i < 3; i++)
		m_vItemList.push_back(tItem);

	m_nCurrentItem = 0;
	
	//InitItems();
}

CProfile::~CProfile()
{
	//for(int i = 0; i < 3; i++)
	//	CSGD_TextureManager::GetInstance()->ReleaseTexture(m_vItemList[i].nItemID);
}

void CProfile::SetProfileName(const char* szName)
{
	if(szName == NULL)
		return;
	strcpy_s(m_szName, 25, szName);
}

void CProfile::SetColor(int nColor)
{
	if(nColor < 0 || nColor > 2)
		return;

	switch(nColor)
	{
	case GREEN:
		{
			m_dwColor = 0xff00ff00;
			m_nColor = nColor;
			break;
		}
	case RED:
		{
			m_dwColor = 0xffff0000;
			m_nColor = nColor;
			break;
		}
	case BLUE:
		{
			m_dwColor = 0xff0000ff;
			m_nColor = nColor;
			break;
		}
	}
}

void CProfile::AddTrophy(bool bTrophy1, bool bTrophy2, bool bTrophy3, int nLevelIndex)
{
	if(nLevelIndex == -1)
	{
		if(bTrophy1)
			m_vTrophyList[GetWhichLevelPlaying()-1].bTrophy1 = true;
		else if(bTrophy2)
			m_vTrophyList[GetWhichLevelPlaying()-1].bTrophy2 = true;
		else if(bTrophy3)
			m_vTrophyList[GetWhichLevelPlaying()-1].bTrophy3 = true;
	}
	else
	{
		if(bTrophy1)
			m_vTrophyList[nLevelIndex-1].bTrophy1 = true;
		else if(bTrophy2)
			m_vTrophyList[nLevelIndex-1].bTrophy2 = true;
		else if(bTrophy3)
			m_vTrophyList[nLevelIndex-1].bTrophy3 = true;
	}
}

char* CProfile::GetPwrUpType(int nIndex)
{
	if(nIndex < 0 || nIndex > 6)
		return NULL;

	switch(nIndex)
	{
	case BALLOON:
		{
			strcpy_s(m_szPwrUpType, 25, "Balloon");
			break;
		}	
	case BRICK:
		{
			strcpy_s(m_szPwrUpType, 25, "Brick");
			break;
		}	
	case GOO:
		{
			strcpy_s(m_szPwrUpType, 25, "Goo");
			break;
		}	
	case METAL_BOOTS:
		{
			strcpy_s(m_szPwrUpType, 25, "MetalBoots");
			break;
		}	
	case MIRROR:
		{
			strcpy_s(m_szPwrUpType, 25, "Mirror");
			break;
		}	
	case PARACHUTE:
		{
			strcpy_s(m_szPwrUpType, 25, "Parachute");
			break;
		}	
	case SPRING:
		{
			strcpy_s(m_szPwrUpType, 25, "Spring");
			break;
		}
	}
	return m_szPwrUpType;
}

bool CProfile::CheckForTrophy(int nTrophy, int nLevelIndex)
{
	if(nLevelIndex < 1 || nLevelIndex > 10)
		return false;

	switch(nTrophy)
	{
	case 1:
		 return m_vTrophyList[nLevelIndex-1].bTrophy1;
		 break;
	case 2:
		return m_vTrophyList[nLevelIndex-1].bTrophy2;
		 break;
	case 3:
		return m_vTrophyList[nLevelIndex-1].bTrophy3;
		 break;
	}
	return false;
}

void CProfile::InitItems()
{
	m_vItemList[RHINO_HORN].nItemID = CSGD_TextureManager::GetInstance()->LoadTexture("Resource/PlayerImages/BS_Horn.png");
	m_vItemList[RHINO_HORN].fScaleX = .5f;
	m_vItemList[RHINO_HORN].fScaleY = .5f;
	m_vItemList[RHINO_HORN].tPos.fX = 28;
	m_vItemList[RHINO_HORN].tPos.fY = 7;
	m_vItemList[RHINO_HORN].fRotation = 8;

	m_vItemList[WHITE_HORN].nItemID = CSGD_TextureManager::GetInstance()->LoadTexture("Resource/PlayerImages/BS_WhiteHorn.png");
	m_vItemList[WHITE_HORN].fScaleX = .5f;
	m_vItemList[WHITE_HORN].fScaleY = .5f;
	m_vItemList[WHITE_HORN].tPos.fX = -12;
	m_vItemList[WHITE_HORN].tPos.fY = -12;
	m_vItemList[WHITE_HORN].fRotation = 8;

	m_vItemList[BOW].nItemID = CSGD_TextureManager::GetInstance()->LoadTexture("Resource/PlayerImages/BS_Bow.png");
	m_vItemList[BOW].fScaleX = -1;
	m_vItemList[BOW].fScaleY = 1;
	m_vItemList[BOW].tPos.fX = 25;
	m_vItemList[BOW].tPos.fY = 5;
	m_vItemList[BOW].fRotation = 32;
}